#include <iostream>
#include <algorithm>

using namespace std;


int main()
{
    int n, k;
    cin >> n >> k;
    int arr[n + 1];
    for (int i = 0; i < n; i++)cin >> arr[i];
    sort(arr, arr + n);
    int left = 0, right = 0;
    int ans = 0;
    while (right < n)
    {
        if (arr[right] - arr[left] <= 2 * k)
        {
            ans = max(ans, right - left + 1);
        }
        else left++;
        right++;
    }
    cout << ans << endl;
    return 0;
}